package com.hdax.controller;

import com.hdax.entity.Employee;
import com.hdax.service.EmployeeService;
import com.hdax.utils.ResultUtil;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 员工账号控制器
 *
 * @author Aizen
 * @date 2022/06/01
 */
@Controller
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    /**
     * 显示员工账号列表
     */
    @RequestMapping("/list")
    public String list() {
        return "system/employee";
    }

    /**
     * 员工账号列表
     *
     * @param page     页面
     * @param limit    限制
     * @param employee 员工
     * @return {@link ResultUtil}
     */
    @ResponseBody
    @PostMapping("/list")
    public ResultUtil listPost(@RequestParam("page")int page, @RequestParam("limit")int limit, @Param("employee") Employee employee) {
        List<Employee> employeeList = employeeService.findAll(page, limit, employee);
        ResultUtil result = ResultUtil.result(employeeList);
        result.setCount(employeeList.size());
        return result;
    }

    /**
     * 修改账号状态
     *
     * @param empCode emp代码
     * @return {@link ResultUtil}
     */
    @ResponseBody
    @PostMapping("/upData")
    public ResultUtil updateEmployee(String empCode,String checked) {
        return employeeService.editEmployeeOffByCode(empCode,checked);
    }



    @PostMapping("/delete")
    public ResultUtil deleteEmployee(Integer empId) {
        return employeeService.deleteById(empId);
    }



















}
